package cn.ffcs.unm.patent.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.patent.dao.PatentDao;
import cn.ffcs.unm.patent.model.Patent;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("patentDao")
public class PatentDaoImpl extends BaseDaoImpl implements PatentDao {

	@Override
	public PageInfo queryInfoByPatent(Patent patent, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select  distinct ja1.MONTH_ID  monthId,ja1.UNIT_ID  单位编码,ja1.PK_PSNDOC_SUB  pkPsndocSub,ja1.RECORDNUM  记录序号, ");
		sb.append(" ja1.ENDDATE  endDate,ja1.GLBDEF1 glbdef1,ja1.GLBDEF2  glbdef2,ja1.GLBDEF3  staffName, ");
		sb.append(" ja1.GLBDEF4  glbdef4,ja1.GLBDEF5  glbdef5,ja1.GLBDEF6  glbdef6,ja1.LASTFLAG  最近记录标志, ");
		sb.append(" ja1.MODIFIEDTIME modifiedTime,ja1.BEGINDATE  beginDate,ja1.CREATIONTIME  创建时间,ja1.TS  时间戳,ja1.	DR	删除标示 ");
		sb.append(" from LDAPM_MPW_HI_PSNDOC_GLBDEF9 ja1 where 1=1");
		
		List<Object> params = new ArrayList<Object>();
		if (null != patent) {
			if (!StrUtil.isEmpty(patent.getMonthId())) {
				sb.append(" AND ja1.MONTH_ID = ? ");
				params.add(patent.getMonthId());
			}
			if (!StrUtil.isEmpty(patent.getStaffName())) {
				sb.append(" AND ja1.GLBDEF3 LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(patent.getStaffName())
						+ "%");
			}
			if (!StrUtil.isEmpty(patent.getGlbdef5())) {
				sb.append(" AND ja1.GLBDEF5 LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(patent.getGlbdef5())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, Patent.class);
	}

}
